package com.lin.cms.service.impl;

import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lin.cms.util.Paging;
import com.lin.cms.criteria.ConfigAttrCriteria;
import com.lin.cms.domain.ConfigAttr;
import com.lin.cms.service.ConfigAttrService;
import com.lin.cms.dao.ConfigAttrMapper;

@Service
public class ConfigAttrServiceImpl implements ConfigAttrService{
	
	public ConfigAttr selectByPrimaryKey(Integer configId){
		return configAttrMapper.selectByPrimaryKey(configId);
	}
	
	public List<ConfigAttr> selectByCriteria(ConfigAttrCriteria criteria){
		return configAttrMapper.selectByCriteria(criteria);
	}
	
	public int deleteByPrimaryKey(Integer configId){
		int actualRowsAffected = 0;
		
		ConfigAttr _oldConfigAttr = configAttrMapper.selectByPrimaryKey(configId);
		
		if (_oldConfigAttr != null) {
			actualRowsAffected = configAttrMapper.deleteByPrimaryKey(configId);
		}
		
		return actualRowsAffected;
	}
	
	public int deleteByCriteria(ConfigAttrCriteria criteria){
		int actualRowsAffected = 0;
		
		List<ConfigAttr> _oldConfigAttr = configAttrMapper.selectByCriteria(criteria);
		
		if (_oldConfigAttr.size() != 0) {
			actualRowsAffected = configAttrMapper.deleteByCriteria(criteria);
		}
		
		return actualRowsAffected;
	}
	
	public int insert(ConfigAttr configAttr){
		return configAttrMapper.insert(configAttr);
	}
	
	public int updateByPrimaryKeySelective(ConfigAttr configAttr){
		int actualRowsAffected = 0;
		
		int advertisingId = configAttr.getConfigId();

		ConfigAttr _oldConfigAttr = configAttrMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldConfigAttr != null) {
			actualRowsAffected = configAttrMapper.updateByPrimaryKeySelective(configAttr);
		}
		
		return actualRowsAffected;
	}
	
	public int updateByPrimaryKey(ConfigAttr configAttr){
		int actualRowsAffected = 0;
		
		int advertisingId = configAttr.getConfigId();

		ConfigAttr _oldConfigAttr = configAttrMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldConfigAttr != null) {
			actualRowsAffected = configAttrMapper.updateByPrimaryKey(configAttr);
		}
		
		return actualRowsAffected;
	}
	
	public List<ConfigAttr> selectByPage(ConfigAttrCriteria criteria) {
		int totalResults = configAttrMapper.countByCriteria(criteria);
		Paging paging = criteria.getPaging();
		paging.setTotalResults(totalResults);
		
		return configAttrMapper.selectByPage(criteria,new RowBounds(paging.getFirstResult(),paging.getMaxResults()));
	}
	
	public int countByCriteria(ConfigAttrCriteria criteria){
		return configAttrMapper.countByCriteria(criteria);
	}
	
	@Autowired
    private ConfigAttrMapper configAttrMapper;
}
